package com.itheima.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TimeAdvice {

    @Pointcut("execution(* com.itheima.dao.BookDao.save(..))")
    public void pt(){}

    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        long startTime = System.currentTimeMillis();

        for (int i = 0; i < 10000; i++) {
            pjp.proceed();
        }

        long endTime = System.currentTimeMillis();
        String methodName = pjp.getSignature().getName();
        String className  = pjp.getSignature().getDeclaringTypeName();

        System.out.println("执行方法" + className + "," + methodName +
                "执行结果为" + (endTime-startTime) +"ms");
        return null;
    }
}
